#此页用于读取数据并安排计算
import os
import sys

import openpyxl

from ut.set_computation_config import read_computation_sheet_date
from entity.shipping_table_entity import ShippingTableEntity
from ut.windows_ui import file_path_query, input_file_name, show_warning
from ut.生成送货单 import print_shipment_table

from ut.生成金额 import print_money_table
from ut.生成预定表 import print_shipping_table, shipping_table_list_entity


#读取出货表
def get_shipping_table():
    try:

        shipping_table_path=file_path_query("读取出货单")
        wb=openpyxl.load_workbook(shipping_table_path,data_only=True)
        sheet_name=input_file_name("工作表名")
        ws=wb[sheet_name]
    except Exception as e:
        show_warning(f"文件读取失败，请重新选择{e}")
        exit(e)

    shipping_list=[]
    for i in range(2,ws.max_row+1):
        if ws.cell(i,1).value=="" or ws.cell(i,1).value is None:
            break
        shipping_list.append(ShippingTableEntity(ws.cell(i,1).value,ws.cell(i,2).value,ws.cell(i,3).value))
    return shipping_list

shipping_table_list=get_shipping_table()
compute_table_list=read_computation_sheet_date()
date = input_file_name('请输入出货日期：')
shipping_list=shipping_table_list_entity(compute_table_list, shipping_table_list)
#打印出货预定表
print_shipping_table(shipping_list,date)

#打印金额表
print_money_table(shipping_table_list,compute_table_list,date)

#打印送货单
print_shipment_table(shipping_list,date)



# if __name__ == '__main__':
#     print_shipment_table(shipping_list,date)